# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import MySQLdb

# useful for handling different item types with a single interface
from itemadapter import ItemAdapter

# 连接数据库
conn = MySQLdb.connect(
    host="localhost",   # mysql所在的主机的ip
    port=3306,          # mysql的端口号
    user="root",        # mysql的用户名
    password="123456",  # mysql的密码
    db="reptiles",      # 要使用的库名
    charset="utf8",     # 连接中使用的字符集

)
cursor = conn.cursor(MySQLdb.cursors.DictCursor)  # 获取游标对象,里面可以为空,这样写是为了显示全面的信息

class EkkoPipeline:
    def process_item(self, item, spider):

        """
        在这里进行数据的存储,
        :param item:
        :param spider:
        :return:
        """
        list = [item["job_name"], item["job_salary"]]
        sql = "insert into day6_51job values (%s,%s)"
        last = cursor.execute(sql, list)
        conn.commit()
# cursor.close()
# conn.close()

        return item
